package com.hyzx.qbasic.admin.domain.repository.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hyzx.qbasic.admin.model.po.CmsContentPO;
import com.hyzx.qbasic.admin.model.po.CmsPagedContentPO;
import com.hyzx.qbasic.admin.model.vo.req.admin.GetCmsContentListReq;
import com.hyzx.qbasic.admin.domain.dao.CmsContentMapper;
import com.hyzx.qbasic.admin.domain.repository.ICmsContentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by 黄江华 on 2018/7/27
 */

@Repository
public class CmsContentRepositoryImpl implements ICmsContentRepository {

    @Autowired
    private CmsContentMapper contentMapper;

    @Override
    public PageInfo<CmsPagedContentPO> getPagedCmsContentList(GetCmsContentListReq req) {
        PageInfo pageInfo = PageHelper.startPage(req.getPageNum(), req.getPageSize())
                .doSelectPageInfo(() -> contentMapper.getPagedCmsContentList(req.getContentStatus(), req.getKeyword(), req.getChannelId()));

        return pageInfo;
    }

    @Override
    public boolean addCmsContent(CmsContentPO cmsContent) {
        return contentMapper.addCmsContent(cmsContent) > 0;
    }

    @Override
    public CmsContentPO getCmsContentInfo(String contentId) {
        return contentMapper.getCmsContentInfo(contentId);
    }

    @Override
    public boolean editCmsContent(CmsContentPO cmsContent) {
        return contentMapper.editCmsContent(cmsContent) > 0;
    }

    @Override
    public boolean publish(String contentId) {
        return contentMapper.publish(contentId) > 0;
    }

    @Override
    public Integer getContentStatus(String contentId) {
        return contentMapper.getContentStatus(contentId);
    }

    @Override
    public Integer getContentChannel(String contentId) {
        return contentMapper.getContentChannel(contentId);
    }

    @Override
    public boolean auditComplete(String contentId, int contentStatus) {
        return contentMapper.auditComplete(contentId, contentStatus) > 0;
    }

    @Override
    public boolean deleteContent(List<String> contentIdList) {
        return contentMapper.deleteContent(contentIdList) > 0;
    }

    @Override
    public boolean restoreContent(List<String> contentIdList) {
        return contentMapper.restoreContent(contentIdList) > 0;
    }

    @Override
    public PageInfo<CmsPagedContentPO> getAuditList(int pageNum, int pageSize, int userId) {
        PageInfo pageInfo = PageHelper.startPage(pageNum, pageSize)
                .doSelectPageInfo(() -> contentMapper.getAuditList(userId));

        return pageInfo;

    }
}
